ARG DOCKER_MIRROR=public.ecr.aws/docker/library
ARG JDK_VERSION=11

# 根据JDK版本选择基础镜像
FROM ${DOCKER_MIRROR}/openjdk:${JDK_VERSION}-jre-slim

# 更换apt源为阿里云源
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \
    sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list

# 设置时区为 GMT+8
RUN apt-get update && \
    apt-get install -y tzdata curl && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ENV TZ=Asia/Shanghai

# 设置工作目录
WORKDIR /app

# 复制构建好的 JAR 文件
COPY target/*.jar app.jar

# 设置环境变量
ENV SPRING_PROFILES_ACTIVE=prod
ENV SERVER_PORT=8080
ENV LOG_PATH=/app/logs

# 创建日志目录
RUN mkdir -p ${LOG_PATH}

# 暴露端口
EXPOSE ${SERVER_PORT}

# 设置启动命令
CMD ["sh", "-c", "java -jar app.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE} --server.port=${SERVER_PORT} --logging.file.path=${LOG_PATH}"]
